/*
 * @Date: 2020-09-16 14:35:26
 * @LastEditors: 小枫
 * @LastEditTime: 2020-09-16 20:03:45
 * @FilePath: \feng-blog\app\service\Review.ts
 */
import { Service } from 'egg';

/**
 * Review Service
 */
export default class ReviewService extends Service {
  /**
   * 根据topic_id获取相关评论
   * @param topic_id -article唯一标识符
   */
  public async getReviews(topic_id: number) {
    const { app } = this;
    const reviews = await app.mysql.select('article_review', {
      where: {
        topic_id,
      },
      orders: [[ 'createAt', 'asc' ]],
    });
    return reviews;
  }

  /**
   * 发布评论
   * @param review -评论信息
   */
  public async insertReview(review: object) {
    const { app } = this;
    const insertResult = await app.mysql.insert('reviews', review);
    return insertResult;
  }
}
